import sys
import os
# 添加项目根目录到系统路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from common.train_dict import classify_problem, get_dict_name  # 导入字典查询函数
from common.person_dict import process_persons_list  # 导入人员字典处理模块

def process_bfyrs_section(output_lines: list) -> list:
    """
    处理被反映人信息部分
    
    Args:
        output_lines: 工作流输出的行列表
    
    Returns:
        list: 处理后的被反映人信息列表
    """
    try:
        # 直接从原始输出中提取bfyrs数据
        bfyrs = []
        current_section = None
        array_content = []
        
        for line in output_lines:
            line = line.strip()
            
            # 识别bfyrs部分
            if "bfyrs:" in line:
                current_section = "bfyrs"
                array_content = []
                continue
                
            # 处理bfyrs部分的数据
            if current_section == "bfyrs":
                if line and line.startswith("['") and line.endswith("']"):
                    # 处理数组格式的数据
                    content = line[2:-2]  # 移除首尾的 [' 和 ']
                    items = content.split("', '")
                    for item in items:
                        parts = item.split('&&')
                        if len(parts) >= 5:
                            info = {
                                'mc': parts[0].strip(),
                                'zj': parts[1].strip(),
                                'zw': parts[2].strip(),
                                'dwhdz': parts[3].strip(),
                                'gbglqx': parts[4].strip()
                            }
                            # 处理null值
                            for key in info:
                                if info[key].lower() == 'null':
                                    info[key] = ''
                            bfyrs.append(info)
                elif line == "[]":
                    # 如果是空数组，直接返回空列表
                    bfyrs = []
                    # print("bfyrs: 空数组")
                        
        return bfyrs
    except Exception as e:
        print(f"处理被反映人信息时发生错误: {str(e)}")
        return [] 